<template>
<view class="container">
  <view class="tixian_top">
    <text class="tixian_text">提现到微信零钱</text>
    <text class="tixian_limit">每日可提现5次</text>
  </view>
  <view class="tixian_box">
    <view class="tixian_account">提现金额</view>
    <view class="tixian_input">
      <text style="margin-right:10rpx;">￥</text>
      <input placeholder-class="tixian_input_font" class="tixian_input_font" placeholder="00.00" auto-focus :value="tixianAmount" @input="getUserAmount"></input>
    </view>
    <view class="tixian_item">
      <text style="margin-right:20rpx;">开户行名:</text>
      <input class="tixian_item_input" placeholder="微信绑定的开户行名" :value="reqBankName" @input="getUserTrueBankName"></input>
    </view>
    <view class="tixian_item">
      <text style="margin-right:20rpx;">银行卡号:</text>
      <input class="tixian_item_input" placeholder="微信绑定的银行卡号" :value="reqBankCardNo" @input="getUserTruBankCardNo"></input>
    </view>
    <view class="tixian_item">
      <text style="margin-right:20rpx;">真实姓名:</text>
      <input class="tixian_item_input" placeholder="微信绑定的真实姓名" :value="reqUserTrueName" @input="getUserTrueName"></input>
    </view>
    <view style="font-size:24rpx;margin-top:10rpx;color:#888">提现金额不得少于<text :style="'color:' + setting.platformSetting.defaultColor">￥1.00</text>元，可提金额<text :style="'color:' + setting.platformSetting.defaultColor">￥{{mendian.account.account}}</text>元</view>
    <view class style="font-size:24rpx;margin-top:16rpx;color:#888">
      <view style="margin-right:20rpx">每次最高提现金额<text :style="'color:' + setting.platformSetting.defaultColor">￥500.00</text>元，每天提现<text :style="'color:' + setting.platformSetting.defaultColor">￥2500.00</text>元封顶</view>
    </view>
    <!-- <view class style="font-size:24rpx;margin-top:16rpx;color:#888">
      <view style="margin-right:20rpx"></view>
    </view> -->
    <!-- <view class='tixian_tip'>
      <text></text>
    </view> -->
    <view class="tixian_btn" :style="'background:' + setting.platformSetting.defaultColor||'#ff0000'" @tap="subMitButn">
      <text>提现</text>
    </view>
  </view>
</view>
</template>

<script>

export default {
  data() {
    return {
      money: 10,
      butn_show_loading: false,
      mendian: null,
      tixianAmount: "",
      reqUserTrueName: "",
      reqBankName: "",
      reqBankCardNo: "",
      setting: "",
      loginUser: "",
      properties: "",
    };
  },

  components: {},
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getMendianInfo();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.setData({
      setting: getApp().globalData.setting,
      loginUser: getApp().globalData.loginUser,
      properties: getApp().globalData.properties
    });

    if (getApp().globalData.properties.alias_yue) {
      wx.setNavigationBarTitle({
        title: getApp().globalData.properties.alias_yue + '提现'
      });
    }
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},
  methods: {
    getUserAmount: function (e) {
      this.setData({
        tixianAmount: e.detail.value
      });
    },
    getUserTrueName: function (e) {
      this.setData({
        reqUserTrueName: e.detail.value
      });
    },
    getUserTrueBankName: function (e) {
      this.setData({
        reqBankName: e.detail.value
      });
    },
    getUserTruBankCardNo: function (e) {
      this.setData({
        reqBankCardNo: e.detail.value
      });
    },
    getMendianInfo: function () {
      console.log('-------门店-1-------');
      let params = {};
      var customIndex = getApp().globalData.AddClientUrl("/ge_manager_mendian_info_admin_mendian_json.html", params, 'post');
      var that = this;
      wx.request({
        url: customIndex.url,
        data: customIndex.params,
        header: getApp().globalData.headerPost,
        method: 'POST',
        success: function (res) {
          console.log(res.data);
          if (res.data.errcode == '0') {
            let mendian = res.data.relateObj;
            mendian = that.dellMoney(mendian); //account 账户余额

            that.setData({
              mendian: mendian,
              reqBankName: mendian.bankName || "",
              reqUserTrueName: mendian.bankOwnerName || "",
              reqBankCardNo: mendian.bankAccount || ""
            });
          }
        },
        fail: function (res) {
          getApp().globalData.loadFail();
        }
      });
    },
    dellMoney: function (mendian) {
      mendian.account.account = getApp().globalData.toFix(mendian.account.account);
      mendian.totalEarningAmount = getApp().globalData.toFix(mendian.totalEarningAmount);
      mendian.totalTixianAmount = getApp().globalData.toFix(mendian.totalTixianAmount);
      mendian.waitCompleteOrderDistributeAmount = getApp().globalData.toFix(mendian.waitCompleteOrderDistributeAmount);
      return mendian;
    },
    subMitButn: function () {
      var that = this;
      let tixianAmount = Number(this.tixianAmount || 0);
      let reqUserTrueName = this.reqUserTrueName || "";
      let reqBankName = this.reqBankName || "";
      let reqBankCardNo = this.reqBankCardNo || "";

      if (tixianAmount < 1 || reqUserTrueName == '') {
        console.log('--------1------');
        wx.showModal({
          title: '提示',
          content: '请确认金额与姓名符合要求',
          success: function (res) {
            if (res.confirm) {} else if (res.cancel) {
              console.log('用户点击取消');
            }
          }
        });
        return;
      }

      let wxChatPayParam = {
        tixianAmount: '',
        reqUserTrueName: '',
        reqBankName: '',
        reqBankCardNo: ''
      };
      wxChatPayParam.tixianAmount = Number(tixianAmount);
      wxChatPayParam.reqUserTrueName = reqUserTrueName;
      wxChatPayParam.reqBankName = reqBankName;
      wxChatPayParam.reqBankCardNo = reqBankCardNo;
      this.setData({
        butn_show_loading: true
      });
      let customIndex = getApp().globalData.AddClientUrl("/mendian_manager_req_mendian_tixian.html", wxChatPayParam, 'post');
      wx.showModal({
        title: '提示',
        content: '确认提现？',
        success: function (res) {
          if (res.confirm) {
            wx.request({
              url: customIndex.url,
              data: customIndex.params,
              header: getApp().globalData.headerPost,
              method: 'POST',
              success: function (res) {
                console.log(res);

                if (res.data.id) {
                  wx.showToast({
                    title: '提交成功',
                    icon: 'success',
                    duration: 2000
                  });
                  setTimeout(function () {
                    wx.navigateBack();
                  }, 2000);
                } else {
                  wx.showToast({
                    title: res.data.errMsg || '未知异常',
                    image: '/wxcomponents/images/icons/tip.png',
                    duration: 2000
                  });
                }

                ;
                setTimeout(function () {
                  wx.navigateBack();
                }, 2000);
              },
              fail: function () {},
              complete: function () {
                that.setData({
                  butn_show_loading: false
                });
              }
            });
          } else if (res.cancel) {
            that.setData({
              butn_show_loading: false
            });
            console.log('用户点击取消');
          }
        }
      });
    },
    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  }
};
</script>
<style>
@import "./index.css";
</style>